#include <all_wlib.h>
#pragma hdrstop
//#pragma package(smart_init)
#pragma resource "*.dfm"

#include "int.h"
#include "ozf_TrackCfg.h"
#pragma link "ColorPickerButton"

bool TrackConfigure( TForm *Owner, TrackOptions& op )
  {  HAutoPtr<TOziTrackCfgForm> d( new TOziTrackCfgForm(Owner, op) );
     static int idx = 0;

     d->pages->ActivePageIndex = idx;
     if ( d->ShowModal() == mrOk ) {
       idx = d->pages->ActivePageIndex;
       op = d->op;
       return true;
     } else
       return false;
}

void Track2CfgOptions( TrackOptions& op )
  {
     SOPT( "Track/CState",                (int)op.CState );
     SOPT( "Track/CHeight",               op.CHeight );
     SOPT( "Track/PState",                (int)op.PState );
     SOPT( "Track/PHeight",               op.PHeight );
     SOPT( "Track/PlState",               (int)op.PlState );
     SOPT( "Track/PlHeight",              op.PlHeight );
     SOPT( "Track/Autosave",              op.Autosave );
     SOPT( "Track/LoadAutosave",          op.LoadAutosave );
     SOPT( "Track/AutosaveFile",          op.AutosaveFile.c_str() );
     SOPT( "Track/AutosavePer",           op.AutosavePer );
     SOPT( "CompressData",                op.CompressData );
     SOPT( "Track/Scale",                 op.Scale );
     SOPT( "Track/ResizeSize",            op.ResizeSize );
     SOPT( "Track/PathPointWidth",        op.PathPointWidth );
     SOPT( "Track/PathLineWidth",         op.PathLineWidth );
     SOPT( "Track/PathSelLineColor",      op.PathSelLineColor );
     SOPT( "Track/PathLineColor",         op.PathLineColor );
     SOPT( "Track/DrawPathPoints",        op.DrawPathPoints );
     SOPT( "Track/NearestPointColor",     op.NearestPointColor );
     SOPT( "Track/PathDirectColor",       op.PathDirectColor );
     SOPT( "Track/PathDirectWidth",       op.PathDirectWidth );
     SOPT( "Track/PathCurrentColor",      op.PathCurrentColor );
     SOPT( "Track/PathPointColor",        op.PathPointColor );
     SOPT( "Track/PathSelDirectColor",    op.PathSelDirectColor );
     SOPT( "Track/InfoColor",             op.InfoColor );
     SOPT( "Track/DrawStartTime",         op.DrawStartTime );
     SOPT( "Track/DrawNumber",            op.DrawNumber );
     SOPT( "Track/DrawDist",              op.DrawDist );
     SOPT( "Track/DrawEtaTime",           op.DrawEtaTime );
     SOPT( "Track/DrawAvgSpeed",          op.DrawAvgSpeed );
     SOPT( "Track/BkColor",               op.BkColor );
     SOPT( "Track/GridColor",             op.GridColor );
     SOPT( "Track/DrawInfo",              op.DrawInfo );
     SOPT( "Track/InfoFont",              op.InfoFont );
     SOPT( "Track/InfoFontColor",         op.InfoFontColor );
     SOPT( "Track/PlaceSize",             op.PlaceSize );
     SOPT( "Track/PlaceCenterSize",       op.PlaceCenterSize );
     SOPT( "Track/PlaceColor",            op.PlaceColor );
     SOPT( "Track/PlaceHandleColor",      op.PlaceHandleColor );
     SOPT( "Track/DrawPlaceNum",          op.DrawPlaceNum );
     SOPT( "Track/PlaceNumColor",         op.PlaceNumColor );
     SOPT( "Track/PlaceNumFontColor",     op.PlaceNumFontColor );
     SOPT( "Track/PlaceNumFontSize",      op.PlaceNumFontSize );
     SOPT( "Track/CurLength",             op.CurLength );
     SOPT( "Track/CurLineColor",          op.CurLineColor );
     SOPT( "Track/CurLineWidth",          op.CurLineWidth );
     SOPT( "Track/CurArrowSize",          op.CurArrowSize );
     SOPT( "Track/CurPointWidth",         op.CurPointWidth );
     SOPT( "Track/CurPointColor",         op.CurPointColor );
     SOPT( "AutoMove",                    op.AutoMove );
     SOPT( "LogTrack",                    op.LogTrack );
     SOPT( "Track/Avg",                   op.Avg );
}

void Cfg2TrackOptions( TrackOptions& op )
  {
     op.CState               = (HCaptionButton_t)GOPT( "Track/CState", (int)hcbNone );
     op.CHeight              = GOPT( "Track/CHeight",               45 );
     op.PState               = (HCaptionButton_t)GOPT( "Track/PState", (int)hcbNone );
     op.PHeight              = GOPT( "Track/PHeight",               150 );
     op.PlState              = (HCaptionButton_t)GOPT( "Track/PlState",(int)hcbNone );
     op.PlHeight             = GOPT( "Track/PlHeight",              150 );
     op.Autosave             = GOPT( "Track/Autosave",              true );
     op.LoadAutosave         = GOPT( "Track/LoadAutosave",          true );
     op.AutosaveFile         = GOPT( "Track/AutosaveFile",          "autosave.path" );
     op.AutosavePer          = GOPT( "Track/AutosavePer",           5 );
     op.CompressData         = GOPT( "CompressData",                false );
     op.Scale                = GOPT( "Track/Scale",                 100 );
     op.ResizeSize           = GOPT( "Track/ResizeSize",            10 );
     op.PathPointWidth       = GOPT( "Track/PathPointWidth",        10 );
     op.PathLineWidth        = GOPT( "Track/PathLineWidth",         1 );
     op.PathSelLineColor     = GOPT( "Track/PathSelLineColor",      clLime );
     op.PathLineColor        = GOPT( "Track/PathLineColor",         clGreen );
     op.DrawPathPoints       = GOPT( "Track/DrawPathPoints",        false );
     op.NearestPointColor    = GOPT( "Track/NearestPointColor",     (TColor)0x008080FF );
     op.PathDirectColor      = GOPT( "Track/PathDirectColor",       clLime );
     op.PathDirectWidth      = GOPT( "Track/PathDirectWidth",       1 );
     op.PathCurrentColor     = GOPT( "Track/PathCurrentColor",      clRed );
     op.PathPointColor       = GOPT( "Track/PathPointColor",        clWhite );
     op.PathSelDirectColor   = GOPT( "Track/PathSelDirectColor",    clLime );
     op.InfoColor            = GOPT( "Track/InfoColor",             (TColor)0x00B3FFFF );
     op.DrawStartTime        = GOPT( "Track/DrawStartTime",         true );
     op.DrawNumber           = GOPT( "Track/DrawNumber",            true );
     op.DrawDist             = GOPT( "Track/DrawDist",              true );
     op.DrawEtaTime          = GOPT( "Track/DrawEtaTime",           true );
     op.DrawAvgSpeed         = GOPT( "Track/DrawAvgSpeed",          true );
     op.BkColor              = GOPT( "Track/BkColor",               clBlack);
     op.GridColor            = GOPT( "Track/GridColor",             (TColor)0x00FF8080 );
     op.DrawInfo             = GOPT( "Track/DrawInfo",              true );
     op.InfoFont             = GOPT( "Track/InfoFont",              8 );
     op.InfoFontColor        = GOPT( "Track/InfoFontColor",         clBlack );
     op.PlaceSize            = GOPT( "Track/PlaceSize",             10 );
     op.PlaceCenterSize      = GOPT( "Track/PlaceCenterSize",       20 );
     op.PlaceColor           = GOPT( "Track/PlaceColor",            clLime );
     op.PlaceHandleColor     = GOPT( "Track/PlaceHandleColor",      clLime );
     op.DrawPlaceNum         = GOPT( "Track/DrawPlaceNum",          true );
     op.PlaceNumColor        = GOPT( "Track/PlaceNumColor",         clLime );
     op.PlaceNumFontColor    = GOPT( "Track/PlaceNumFontColor",     clBlack );
     op.PlaceNumFontSize     = GOPT( "Track/PlaceNumFontSize",      12 );
     op.CurLength            = GOPT( "Track/CurLength",             20 );
     op.CurLineColor         = GOPT( "Track/CurLineColor",          (TColor)0x0000CECE );
     op.CurLineWidth         = GOPT( "Track/CurLineWidth",          3 );
     op.CurArrowSize         = GOPT( "Track/CurArrowSize",          10 );
     op.CurPointWidth        = GOPT( "Track/CurPointWidth",         10 );
     op.CurPointColor        = GOPT( "Track/CurPointColor",         clWhite );
     op.AutoMove             = GOPT( "AutoMove",                    true );
     op.LogTrack             = GOPT( "LogTrack",                    true );
     op.Avg                  = GOPT( "Track/Avg",                   10 );
}

//---------------------------------------------------------------------------
__fastcall TOziTrackCfgForm::TOziTrackCfgForm(TComponent* Owner, const TrackOptions& _op)
    : TForm(Owner),
      op(_op)
  {

    //cfg -> Fields
     btnResizeHeight->Position             = op.ResizeSize;
     btnAvg->Position                      = op.Avg;
     btnBkColor->SelectionColor            = op.BkColor;
     btnCurPointWidth->Position            = op.CurPointWidth;
     btnCurLength->Position                = op.CurLength;
     btnCurLineWidth->Position             = op.CurLineWidth;
     btnCurLineColor->SelectionColor       = op.CurLineColor;
     btnCurPointColor->SelectionColor      = op.CurPointColor;
     btnGridColor->SelectionColor          = op.GridColor;
     btnPathLineWidth->Position            = op.PathLineWidth;
     btnPathLineColor->SelectionColor      = op.PathLineColor;
     btnPathPointWidth->Position           = op.PathPointWidth;
     btnPathCurrentColor->SelectionColor   = op.PathCurrentColor;
     btnPathPointColor->SelectionColor     = op.PathPointColor;
     btnPathDirectColor->SelectionColor    = op.PathDirectColor;
     btnPathDirectWidth->Position          = op.PathDirectWidth;
     btnPathSelDirectColor->SelectionColor = op.PathSelDirectColor;
     btnScale->Position                    = op.Scale;
     chDrawInfo->Checked                   = op.DrawInfo;
     btnInfoFont->Position                 = op.InfoFont;
     btnInfoFontColor->SelectionColor      = op.InfoFontColor;
     btnInfoColor->SelectionColor          = op.InfoColor;
     btnNearestPointColor->SelectionColor  = op.NearestPointColor;
     chDrawStartTime->Checked              = op.DrawStartTime;
     chDrawDist->Checked                   = op.DrawDist;
     chDrawEtaTime->Checked                = op.DrawEtaTime;
     chDrawAvgSpeed->Checked               = op.DrawAvgSpeed;
     chDrawPathPoints->Checked             = op.DrawPathPoints;
     chDrawNumber->Checked                 = op.DrawNumber;
     chCompressData->Checked               = op.CompressData;
     chAutosave->Checked                   = op.Autosave;
     btnAutosave->Position                 = op.AutosavePer;
     edtAutosaveFile->Text                 = op.AutosaveFile;
     chLoadAutosave->Checked               = op.LoadAutosave;

     btnPlaceSize->Position                = op.PlaceSize;
     btnPlaceColor->SelectionColor         = op.PlaceColor;
     btnPlaceCenterSize->Position          = op.PlaceCenterSize;
     btnPlaceHandleColor->SelectionColor   = op.PlaceHandleColor;
     chDrawPlaceNum->Checked               = op.DrawPlaceNum;
     btnPlaceNumFontSize->Position         = op.PlaceNumFontSize;
     btnPlaceNumFontColor->SelectionColor  = op.PlaceNumFontColor;
     btnPlaceNumColor->SelectionColor      = op.PlaceNumColor;
}
//---------------------------------------------------------------------------
void __fastcall TOziTrackCfgForm::btnOKClick(TObject *Sender)
  {
    //Fields -> cfg
     op.ResizeSize               = btnResizeHeight->Position;
     op.Avg                      = btnAvg->Position;
     op.BkColor                  = btnBkColor->SelectionColor;
     op.CurPointWidth            = btnCurPointWidth->Position;
     op.CurLength                = btnCurLength->Position;
     op.CurLineWidth             = btnCurLineWidth->Position;
     op.CurLineColor             = btnCurLineColor->SelectionColor;
     op.CurPointColor            = btnCurPointColor->SelectionColor;
     op.GridColor                = btnGridColor->SelectionColor;
     op.PathLineWidth            = btnPathLineWidth->Position;
     op.PathLineColor            = btnPathLineColor->SelectionColor;
     op.PathPointWidth           = btnPathPointWidth->Position;
     op.PathCurrentColor         = btnPathCurrentColor->SelectionColor;
     op.PathPointColor           = btnPathPointColor->SelectionColor;
     op.PathDirectColor          = btnPathDirectColor->SelectionColor;
     op.PathDirectWidth          = btnPathDirectWidth->Position;
     op.PathSelDirectColor       = btnPathSelDirectColor->SelectionColor;
     op.Scale                    = btnScale->Position;
     op.DrawInfo                 = chDrawInfo->Checked;
     op.InfoFont                 = btnInfoFont->Position;
     op.InfoFontColor            = btnInfoFontColor->SelectionColor;
     op.InfoColor                = btnInfoColor->SelectionColor;
     op.NearestPointColor        = btnNearestPointColor->SelectionColor;
     op.DrawStartTime            = chDrawStartTime->Checked;
     op.DrawDist                 = chDrawDist->Checked;
     op.DrawEtaTime              = chDrawEtaTime->Checked;
     op.DrawAvgSpeed             = chDrawAvgSpeed->Checked;
     op.DrawPathPoints           = chDrawPathPoints->Checked;
     op.DrawNumber               = chDrawNumber->Checked;
     op.CompressData             = chCompressData->Checked;
     op.Autosave                 = chAutosave->Checked;
     op.AutosavePer              = btnAutosave->Position;
     op.AutosaveFile             = edtAutosaveFile->Text.c_str();
     op.LoadAutosave             = chLoadAutosave->Checked;

     op.PlaceSize                = btnPlaceSize->Position;
     op.PlaceColor               = btnPlaceColor->SelectionColor;
     op.PlaceCenterSize          = btnPlaceCenterSize->Position;
     op.PlaceHandleColor         = btnPlaceHandleColor->SelectionColor;
     op.DrawPlaceNum             = chDrawPlaceNum->Checked;
     op.PlaceNumFontSize         = btnPlaceNumFontSize->Position;
     op.PlaceNumFontColor        = btnPlaceNumFontColor->SelectionColor;
     op.PlaceNumColor            = btnPlaceNumColor->SelectionColor;

     ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TOziTrackCfgForm::FormKeyDown(TObject *Sender, WORD &Key,TShiftState Shift)
  {
    if ( Key == VK_ESCAPE )
      ModalResult = mrCancel;
}
//---------------------------------------------------------------------------

